package com.wjjun.data.uitls;

import android.util.Log;

import java.net.URLDecoder;
import java.util.Date;

/**
 * Created by Administrator on 2018/12/13.
 * 网络日志
 */

public class HttpLog implements HttpLoggingInterceptor.Logger {
    public static boolean showLog = true;

    @Override
    public void log(String msg) {

        try {
            msg = URLDecoder.decode(msg, "utf-8");
            if (showLog) {
                String tag = "网络日志";
                if (msg == null || msg.length() == 0) {
                    return;
                }
                int segmentSize = 2048;
                long length = msg.length();
                // 长度小于等于限制直接打印
                if (length <= segmentSize) {
                    Log.i(tag, msg);
                } else {
                    // 循环分段打印日志
                    while (msg.length() > segmentSize) {
                        String logContent = msg.substring(0, segmentSize);
                        msg = msg.replace(logContent, "");
                        Log.i(tag, logContent);
                    }
                    // 打印剩余日志
                    Log.i(tag, msg);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
